﻿#region Using directives

using System;
using System.Data;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;

using BesAsm.MasterData.Entities;
using BesAsm.MasterData.Data;

#endregion

namespace BesAsm.MasterData.Data.Bases
{	
	///<summary>
	/// This class is the base class for any <see cref="SscZingerProviderBase"/> implementation.
	/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
	///</summary>
	public abstract partial class SscZingerProviderBaseCore : EntityProviderBase<BesAsm.MasterData.Entities.SscZinger, BesAsm.MasterData.Entities.SscZingerKey>
	{		
		#region Get from Many To Many Relationship Functions
		#endregion	
		
		#region Delete Methods

		/// <summary>
		/// 	Deletes a row from the DataSource.
		/// </summary>
		/// <param name="transactionManager">A <see cref="TransactionManager"/> object.</param>
		/// <param name="key">The unique identifier of the row to delete.</param>
		/// <returns>Returns true if operation suceeded.</returns>
		public override bool Delete(TransactionManager transactionManager, BesAsm.MasterData.Entities.SscZingerKey key)
		{
			return Delete(transactionManager, key.SscZingerId);
		}
		
		/// <summary>
		/// 	Deletes a row from the DataSource.
		/// </summary>
		/// <param name="_sscZingerId">Primary key, SSC zinger ID. Primary Key.</param>
		/// <remarks>Deletes based on primary key(s).</remarks>
		/// <returns>Returns true if operation suceeded.</returns>
		public bool Delete(System.Int32 _sscZingerId)
		{
			return Delete(null, _sscZingerId);
		}
		
		/// <summary>
		/// 	Deletes a row from the DataSource.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_sscZingerId">Primary key, SSC zinger ID. Primary Key.</param>
		/// <remarks>Deletes based on primary key(s).</remarks>
		/// <returns>Returns true if operation suceeded.</returns>
		public abstract bool Delete(TransactionManager transactionManager, System.Int32 _sscZingerId);		
		
		#endregion Delete Methods
		
		#region Get By Foreign Key Functions
	
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_SSC_ZINGERS_NODES key.
		///		FK_SSC_ZINGERS_NODES Description: 
		/// </summary>
		/// <param name="_nodeId">Foreign key to NODES (for draining node)</param>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.SscZinger objects.</returns>
		public TList<SscZinger> GetByNodeId(System.Int32 _nodeId)
		{
			int count = -1;
			return GetByNodeId(_nodeId, 0,int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_SSC_ZINGERS_NODES key.
		///		FK_SSC_ZINGERS_NODES Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_nodeId">Foreign key to NODES (for draining node)</param>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.SscZinger objects.</returns>
		/// <remarks></remarks>
		public TList<SscZinger> GetByNodeId(TransactionManager transactionManager, System.Int32 _nodeId)
		{
			int count = -1;
			return GetByNodeId(transactionManager, _nodeId, 0, int.MaxValue, out count);
		}
		
			/// <summary>
		/// 	Gets rows from the datasource based on the FK_SSC_ZINGERS_NODES key.
		///		FK_SSC_ZINGERS_NODES Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_nodeId">Foreign key to NODES (for draining node)</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		///  <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.SscZinger objects.</returns>
		public TList<SscZinger> GetByNodeId(TransactionManager transactionManager, System.Int32 _nodeId, int start, int pageLength)
		{
			int count = -1;
			return GetByNodeId(transactionManager, _nodeId, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_SSC_ZINGERS_NODES key.
		///		fkSscZingersNodes Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_nodeId">Foreign key to NODES (for draining node)</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.SscZinger objects.</returns>
		public TList<SscZinger> GetByNodeId(System.Int32 _nodeId, int start, int pageLength)
		{
			int count =  -1;
			return GetByNodeId(null, _nodeId, start, pageLength,out count);	
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_SSC_ZINGERS_NODES key.
		///		fkSscZingersNodes Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_nodeId">Foreign key to NODES (for draining node)</param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.SscZinger objects.</returns>
		public TList<SscZinger> GetByNodeId(System.Int32 _nodeId, int start, int pageLength,out int count)
		{
			return GetByNodeId(null, _nodeId, start, pageLength, out count);	
		}
						
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_SSC_ZINGERS_NODES key.
		///		FK_SSC_ZINGERS_NODES Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_nodeId">Foreign key to NODES (for draining node)</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">The total number of records.</param>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.SscZinger objects.</returns>
		public abstract TList<SscZinger> GetByNodeId(TransactionManager transactionManager, System.Int32 _nodeId, int start, int pageLength, out int count);
		
	
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_SSC_ZINGERS_SSCS key.
		///		FK_SSC_ZINGERS_SSCS Description: 
		/// </summary>
		/// <param name="_sscId">Foreign key to SSCS</param>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.SscZinger objects.</returns>
		public TList<SscZinger> GetBySscId(System.Int32 _sscId)
		{
			int count = -1;
			return GetBySscId(_sscId, 0,int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_SSC_ZINGERS_SSCS key.
		///		FK_SSC_ZINGERS_SSCS Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_sscId">Foreign key to SSCS</param>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.SscZinger objects.</returns>
		/// <remarks></remarks>
		public TList<SscZinger> GetBySscId(TransactionManager transactionManager, System.Int32 _sscId)
		{
			int count = -1;
			return GetBySscId(transactionManager, _sscId, 0, int.MaxValue, out count);
		}
		
			/// <summary>
		/// 	Gets rows from the datasource based on the FK_SSC_ZINGERS_SSCS key.
		///		FK_SSC_ZINGERS_SSCS Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_sscId">Foreign key to SSCS</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		///  <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.SscZinger objects.</returns>
		public TList<SscZinger> GetBySscId(TransactionManager transactionManager, System.Int32 _sscId, int start, int pageLength)
		{
			int count = -1;
			return GetBySscId(transactionManager, _sscId, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_SSC_ZINGERS_SSCS key.
		///		fkSscZingersSscs Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_sscId">Foreign key to SSCS</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.SscZinger objects.</returns>
		public TList<SscZinger> GetBySscId(System.Int32 _sscId, int start, int pageLength)
		{
			int count =  -1;
			return GetBySscId(null, _sscId, start, pageLength,out count);	
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_SSC_ZINGERS_SSCS key.
		///		fkSscZingersSscs Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_sscId">Foreign key to SSCS</param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.SscZinger objects.</returns>
		public TList<SscZinger> GetBySscId(System.Int32 _sscId, int start, int pageLength,out int count)
		{
			return GetBySscId(null, _sscId, start, pageLength, out count);	
		}
						
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_SSC_ZINGERS_SSCS key.
		///		FK_SSC_ZINGERS_SSCS Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_sscId">Foreign key to SSCS</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">The total number of records.</param>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.SscZinger objects.</returns>
		public abstract TList<SscZinger> GetBySscId(TransactionManager transactionManager, System.Int32 _sscId, int start, int pageLength, out int count);
		
		#endregion

		#region Get By Index Functions
		
		/// <summary>
		/// 	Gets a row from the DataSource based on its primary key.
		/// </summary>
		/// <param name="transactionManager">A <see cref="TransactionManager"/> object.</param>
		/// <param name="key">The unique identifier of the row to retrieve.</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <returns>Returns an instance of the Entity class.</returns>
		public override BesAsm.MasterData.Entities.SscZinger Get(TransactionManager transactionManager, BesAsm.MasterData.Entities.SscZingerKey key, int start, int pageLength)
		{
			return GetBySscZingerId(transactionManager, key.SscZingerId, start, pageLength);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the primary key PK_SSC_ZINGERS index.
		/// </summary>
		/// <param name="_sscZingerId">Primary key, SSC zinger ID</param>
		/// <returns>Returns an instance of the <see cref="BesAsm.MasterData.Entities.SscZinger"/> class.</returns>
		public BesAsm.MasterData.Entities.SscZinger GetBySscZingerId(System.Int32 _sscZingerId)
		{
			int count = -1;
			return GetBySscZingerId(null,_sscZingerId, 0, int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_SSC_ZINGERS index.
		/// </summary>
		/// <param name="_sscZingerId">Primary key, SSC zinger ID</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="BesAsm.MasterData.Entities.SscZinger"/> class.</returns>
		public BesAsm.MasterData.Entities.SscZinger GetBySscZingerId(System.Int32 _sscZingerId, int start, int pageLength)
		{
			int count = -1;
			return GetBySscZingerId(null, _sscZingerId, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_SSC_ZINGERS index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_sscZingerId">Primary key, SSC zinger ID</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="BesAsm.MasterData.Entities.SscZinger"/> class.</returns>
		public BesAsm.MasterData.Entities.SscZinger GetBySscZingerId(TransactionManager transactionManager, System.Int32 _sscZingerId)
		{
			int count = -1;
			return GetBySscZingerId(transactionManager, _sscZingerId, 0, int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_SSC_ZINGERS index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_sscZingerId">Primary key, SSC zinger ID</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="BesAsm.MasterData.Entities.SscZinger"/> class.</returns>
		public BesAsm.MasterData.Entities.SscZinger GetBySscZingerId(TransactionManager transactionManager, System.Int32 _sscZingerId, int start, int pageLength)
		{
			int count = -1;
			return GetBySscZingerId(transactionManager, _sscZingerId, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_SSC_ZINGERS index.
		/// </summary>
		/// <param name="_sscZingerId">Primary key, SSC zinger ID</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="BesAsm.MasterData.Entities.SscZinger"/> class.</returns>
		public BesAsm.MasterData.Entities.SscZinger GetBySscZingerId(System.Int32 _sscZingerId, int start, int pageLength, out int count)
		{
			return GetBySscZingerId(null, _sscZingerId, start, pageLength, out count);
		}
		
				
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_SSC_ZINGERS index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_sscZingerId">Primary key, SSC zinger ID</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">The total number of records.</param>
		/// <returns>Returns an instance of the <see cref="BesAsm.MasterData.Entities.SscZinger"/> class.</returns>
		public abstract BesAsm.MasterData.Entities.SscZinger GetBySscZingerId(TransactionManager transactionManager, System.Int32 _sscZingerId, int start, int pageLength, out int count);
						
		/// <summary>
		/// 	Gets rows from the datasource based on the primary key R145_ROWID_SDE_UK index.
		/// </summary>
		/// <param name="_objectid"></param>
		/// <returns>Returns an instance of the <see cref="BesAsm.MasterData.Entities.SscZinger"/> class.</returns>
		public BesAsm.MasterData.Entities.SscZinger GetByObjectid(System.Int32 _objectid)
		{
			int count = -1;
			return GetByObjectid(null,_objectid, 0, int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the R145_ROWID_SDE_UK index.
		/// </summary>
		/// <param name="_objectid"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="BesAsm.MasterData.Entities.SscZinger"/> class.</returns>
		public BesAsm.MasterData.Entities.SscZinger GetByObjectid(System.Int32 _objectid, int start, int pageLength)
		{
			int count = -1;
			return GetByObjectid(null, _objectid, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the R145_ROWID_SDE_UK index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_objectid"></param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="BesAsm.MasterData.Entities.SscZinger"/> class.</returns>
		public BesAsm.MasterData.Entities.SscZinger GetByObjectid(TransactionManager transactionManager, System.Int32 _objectid)
		{
			int count = -1;
			return GetByObjectid(transactionManager, _objectid, 0, int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the R145_ROWID_SDE_UK index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_objectid"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="BesAsm.MasterData.Entities.SscZinger"/> class.</returns>
		public BesAsm.MasterData.Entities.SscZinger GetByObjectid(TransactionManager transactionManager, System.Int32 _objectid, int start, int pageLength)
		{
			int count = -1;
			return GetByObjectid(transactionManager, _objectid, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the R145_ROWID_SDE_UK index.
		/// </summary>
		/// <param name="_objectid"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="BesAsm.MasterData.Entities.SscZinger"/> class.</returns>
		public BesAsm.MasterData.Entities.SscZinger GetByObjectid(System.Int32 _objectid, int start, int pageLength, out int count)
		{
			return GetByObjectid(null, _objectid, start, pageLength, out count);
		}
		
				
		/// <summary>
		/// 	Gets rows from the datasource based on the R145_ROWID_SDE_UK index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_objectid"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">The total number of records.</param>
		/// <returns>Returns an instance of the <see cref="BesAsm.MasterData.Entities.SscZinger"/> class.</returns>
		public abstract BesAsm.MasterData.Entities.SscZinger GetByObjectid(TransactionManager transactionManager, System.Int32 _objectid, int start, int pageLength, out int count);
						
		#endregion "Get By Index Functions"
	
		#region Custom Methods
		
		
		#endregion

		#region Helper Functions	
		
		/// <summary>
		/// Fill a TList&lt;SscZinger&gt; From a DataReader.
		/// </summary>
		/// <param name="reader">Datareader</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">number of rows.</param>
		/// <returns>a <see cref="TList&lt;SscZinger&gt;"/></returns>
		public static TList<SscZinger> Fill(IDataReader reader, TList<SscZinger> rows, int start, int pageLength)
		{
			NetTiersProvider currentProvider = DataRepository.Provider;
            bool useEntityFactory = currentProvider.UseEntityFactory;
            bool enableEntityTracking = currentProvider.EnableEntityTracking;
            LoadPolicy currentLoadPolicy = currentProvider.CurrentLoadPolicy;
			Type entityCreationFactoryType = currentProvider.EntityCreationalFactoryType;
			
			// advance to the starting row
			for (int i = 0; i < start; i++)
			{
				if (!reader.Read())
				return rows; // not enough rows, just return
			}
			for (int i = 0; i < pageLength; i++)
			{
				if (!reader.Read())
					break; // we are done
					
				string key = null;
				
				BesAsm.MasterData.Entities.SscZinger c = null;
				if (useEntityFactory)
				{
					key = new System.Text.StringBuilder("SscZinger")
					.Append("|").Append((System.Int32)reader[((int)SscZingerColumn.SscZingerId - 1)]).ToString();
					c = EntityManager.LocateOrCreate<SscZinger>(
					key.ToString(), // EntityTrackingKey
					"SscZinger",  //Creational Type
					entityCreationFactoryType,  //Factory used to create entity
					enableEntityTracking); // Track this entity?
				}
				else
				{
					c = new BesAsm.MasterData.Entities.SscZinger();
				}
				
				if (!enableEntityTracking ||
					c.EntityState == EntityState.Added ||
					(enableEntityTracking &&
					
						(
							(currentLoadPolicy == LoadPolicy.PreserveChanges && c.EntityState == EntityState.Unchanged) ||
							(currentLoadPolicy == LoadPolicy.DiscardChanges && c.EntityState != EntityState.Unchanged)
						)
					))
				{
					c.SuppressEntityEvents = true;
					c.Objectid = (System.Int32)reader[((int)SscZingerColumn.Objectid - 1)];
					c.SscZingerId = (System.Int32)reader[((int)SscZingerColumn.SscZingerId - 1)];
					c.OriginalSscZingerId = c.SscZingerId;
					c.SscId = (System.Int32)reader[((int)SscZingerColumn.SscId - 1)];
					c.NodeId = (System.Int32)reader[((int)SscZingerColumn.NodeId - 1)];
					c.Shape = (reader.IsDBNull(((int)SscZingerColumn.Shape - 1)))?null:(System.Object)reader[((int)SscZingerColumn.Shape - 1)];
					c.EntityTrackingKey = key;
					c.AcceptChanges();
					c.SuppressEntityEvents = false;
				}
				rows.Add(c);
			}
		return rows;
		}		
		/// <summary>
		/// Refreshes the <see cref="BesAsm.MasterData.Entities.SscZinger"/> object from the <see cref="IDataReader"/>.
		/// </summary>
		/// <param name="reader">The <see cref="IDataReader"/> to read from.</param>
		/// <param name="entity">The <see cref="BesAsm.MasterData.Entities.SscZinger"/> object to refresh.</param>
		public static void RefreshEntity(IDataReader reader, BesAsm.MasterData.Entities.SscZinger entity)
		{
			if (!reader.Read()) return;
			
			entity.Objectid = (System.Int32)reader[((int)SscZingerColumn.Objectid - 1)];
			entity.SscZingerId = (System.Int32)reader[((int)SscZingerColumn.SscZingerId - 1)];
			entity.OriginalSscZingerId = (System.Int32)reader["ssc_zinger_id"];
			entity.SscId = (System.Int32)reader[((int)SscZingerColumn.SscId - 1)];
			entity.NodeId = (System.Int32)reader[((int)SscZingerColumn.NodeId - 1)];
			entity.Shape = (reader.IsDBNull(((int)SscZingerColumn.Shape - 1)))?null:(System.Object)reader[((int)SscZingerColumn.Shape - 1)];
			entity.AcceptChanges();
		}
		
		/// <summary>
		/// Refreshes the <see cref="BesAsm.MasterData.Entities.SscZinger"/> object from the <see cref="DataSet"/>.
		/// </summary>
		/// <param name="dataSet">The <see cref="DataSet"/> to read from.</param>
		/// <param name="entity">The <see cref="BesAsm.MasterData.Entities.SscZinger"/> object.</param>
		public static void RefreshEntity(DataSet dataSet, BesAsm.MasterData.Entities.SscZinger entity)
		{
			DataRow dataRow = dataSet.Tables[0].Rows[0];
			
			entity.Objectid = (System.Int32)dataRow["OBJECTID"];
			entity.SscZingerId = (System.Int32)dataRow["ssc_zinger_id"];
			entity.OriginalSscZingerId = (System.Int32)dataRow["ssc_zinger_id"];
			entity.SscId = (System.Int32)dataRow["ssc_id"];
			entity.NodeId = (System.Int32)dataRow["node_id"];
			entity.Shape = Convert.IsDBNull(dataRow["SHAPE"]) ? null : (System.Object)dataRow["SHAPE"];
			entity.AcceptChanges();
		}
		#endregion 
		
		#region DeepLoad Methods
		/// <summary>
		/// Deep Loads the <see cref="IEntity"/> object with criteria based of the child 
		/// property collections only N Levels Deep based on the <see cref="DeepLoadType"/>.
		/// </summary>
		/// <remarks>
		/// Use this method with caution as it is possible to DeepLoad with Recursion and traverse an entire object graph.
		/// </remarks>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="entity">The <see cref="BesAsm.MasterData.Entities.SscZinger"/> object to load.</param>
		/// <param name="deep">Boolean. A flag that indicates whether to recursively save all Property Collection that are descendants of this instance. If True, saves the complete object graph below this object. If False, saves this object only. </param>
		/// <param name="deepLoadType">DeepLoadType Enumeration to Include/Exclude object property collections from Load.</param>
		/// <param name="childTypes">BesAsm.MasterData.Entities.SscZinger Property Collection Type Array To Include or Exclude from Load</param>
		/// <param name="innerList">A collection of child types for easy access.</param>
	    /// <exception cref="ArgumentNullException">entity or childTypes is null.</exception>
	    /// <exception cref="ArgumentException">deepLoadType has invalid value.</exception>
		public override void DeepLoad(TransactionManager transactionManager, BesAsm.MasterData.Entities.SscZinger entity, bool deep, DeepLoadType deepLoadType, System.Type[] childTypes, DeepSession innerList)
		{
			if(entity == null)
				return;

			#region NodeIdSource	
			if (CanDeepLoad(entity, "Node|NodeIdSource", deepLoadType, innerList) 
				&& entity.NodeIdSource == null)
			{
				object[] pkItems = new object[1];
				pkItems[0] = entity.NodeId;
				Node tmpEntity = EntityManager.LocateEntity<Node>(EntityLocator.ConstructKeyFromPkItems(typeof(Node), pkItems), DataRepository.Provider.EnableEntityTracking);
				if (tmpEntity != null)
					entity.NodeIdSource = tmpEntity;
				else
					entity.NodeIdSource = DataRepository.NodeProvider.GetByNodeId(transactionManager, entity.NodeId);		
				
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'NodeIdSource' loaded. key " + entity.EntityTrackingKey);
				#endif 
				
				if (deep && entity.NodeIdSource != null)
				{
					innerList.SkipChildren = true;
					DataRepository.NodeProvider.DeepLoad(transactionManager, entity.NodeIdSource, deep, deepLoadType, childTypes, innerList);
					innerList.SkipChildren = false;
				}
					
			}
			#endregion NodeIdSource

			#region SscIdSource	
			if (CanDeepLoad(entity, "Ssc|SscIdSource", deepLoadType, innerList) 
				&& entity.SscIdSource == null)
			{
				object[] pkItems = new object[1];
				pkItems[0] = entity.SscId;
				Ssc tmpEntity = EntityManager.LocateEntity<Ssc>(EntityLocator.ConstructKeyFromPkItems(typeof(Ssc), pkItems), DataRepository.Provider.EnableEntityTracking);
				if (tmpEntity != null)
					entity.SscIdSource = tmpEntity;
				else
					entity.SscIdSource = DataRepository.SscProvider.GetBySscId(transactionManager, entity.SscId);		
				
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'SscIdSource' loaded. key " + entity.EntityTrackingKey);
				#endif 
				
				if (deep && entity.SscIdSource != null)
				{
					innerList.SkipChildren = true;
					DataRepository.SscProvider.DeepLoad(transactionManager, entity.SscIdSource, deep, deepLoadType, childTypes, innerList);
					innerList.SkipChildren = false;
				}
					
			}
			#endregion SscIdSource
			
			//used to hold DeepLoad method delegates and fire after all the local children have been loaded.
			Dictionary<string, KeyValuePair<Delegate, object>> deepHandles = new Dictionary<string, KeyValuePair<Delegate, object>>();
			
			//Fire all DeepLoad Items
			foreach(KeyValuePair<Delegate, object> pair in deepHandles.Values)
		    {
                pair.Key.DynamicInvoke((object[])pair.Value);
		    }
			deepHandles = null;
		}
		
		#endregion 
		
		#region DeepSave Methods

		/// <summary>
		/// Deep Save the entire object graph of the BesAsm.MasterData.Entities.SscZinger object with criteria based of the child 
		/// Type property array and DeepSaveType.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="entity">BesAsm.MasterData.Entities.SscZinger instance</param>
		/// <param name="deepSaveType">DeepSaveType Enumeration to Include/Exclude object property collections from Save.</param>
		/// <param name="childTypes">BesAsm.MasterData.Entities.SscZinger Property Collection Type Array To Include or Exclude from Save</param>
		/// <param name="innerList">A Hashtable of child types for easy access.</param>
		public override bool DeepSave(TransactionManager transactionManager, BesAsm.MasterData.Entities.SscZinger entity, DeepSaveType deepSaveType, System.Type[] childTypes, DeepSession innerList)
		{	
			if (entity == null)
				return false;
							
			#region Composite Parent Properties
			//Save Source Composite Properties, however, don't call deep save on them.  
			//So they only get saved a single level deep.
			
			#region NodeIdSource
			if (CanDeepSave(entity, "Node|NodeIdSource", deepSaveType, innerList) 
				&& entity.NodeIdSource != null)
			{
				DataRepository.NodeProvider.Save(transactionManager, entity.NodeIdSource);
				entity.NodeId = entity.NodeIdSource.NodeId;
			}
			#endregion 
			
			#region SscIdSource
			if (CanDeepSave(entity, "Ssc|SscIdSource", deepSaveType, innerList) 
				&& entity.SscIdSource != null)
			{
				DataRepository.SscProvider.Save(transactionManager, entity.SscIdSource);
				entity.SscId = entity.SscIdSource.SscId;
			}
			#endregion 
			#endregion Composite Parent Properties

			// Save Root Entity through Provider
			if (!entity.IsDeleted)
				this.Save(transactionManager, entity);
			
			//used to hold DeepSave method delegates and fire after all the local children have been saved.
			Dictionary<string, KeyValuePair<Delegate, object>> deepHandles = new Dictionary<string, KeyValuePair<Delegate, object>>();
			//Fire all DeepSave Items
			foreach(KeyValuePair<Delegate, object> pair in deepHandles.Values)
		    {
                pair.Key.DynamicInvoke((object[])pair.Value);
		    }
			
			// Save Root Entity through Provider, if not already saved in delete mode
			if (entity.IsDeleted)
				this.Save(transactionManager, entity);
				

			deepHandles = null;
						
			return true;
		}
		#endregion
	} // end class
	
	#region SscZingerChildEntityTypes
	
	///<summary>
	/// Enumeration used to expose the different child entity types 
	/// for child properties in <c>BesAsm.MasterData.Entities.SscZinger</c>
	///</summary>
	public enum SscZingerChildEntityTypes
	{
		
		///<summary>
		/// Composite Property for <c>Node</c> at NodeIdSource
		///</summary>
		[ChildEntityType(typeof(Node))]
		Node,
			
		///<summary>
		/// Composite Property for <c>Ssc</c> at SscIdSource
		///</summary>
		[ChildEntityType(typeof(Ssc))]
		Ssc,
		}
	
	#endregion SscZingerChildEntityTypes
	
	#region SscZingerFilterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="SqlFilterBuilder&lt;SscZingerColumn&gt;"/> class
	/// that is used exclusively with a <see cref="SscZinger"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class SscZingerFilterBuilder : SqlFilterBuilder<SscZingerColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the SscZingerFilterBuilder class.
		/// </summary>
		public SscZingerFilterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the SscZingerFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public SscZingerFilterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the SscZingerFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public SscZingerFilterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion SscZingerFilterBuilder
	
	#region SscZingerParameterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="ParameterizedSqlFilterBuilder&lt;SscZingerColumn&gt;"/> class
	/// that is used exclusively with a <see cref="SscZinger"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class SscZingerParameterBuilder : ParameterizedSqlFilterBuilder<SscZingerColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the SscZingerParameterBuilder class.
		/// </summary>
		public SscZingerParameterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the SscZingerParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public SscZingerParameterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the SscZingerParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public SscZingerParameterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion SscZingerParameterBuilder
	
	#region SscZingerSortBuilder
    
    /// <summary>
    /// A strongly-typed instance of the <see cref="SqlSortBuilder&lt;SscZingerColumn&gt;"/> class
	/// that is used exclusively with a <see cref="SscZinger"/> object.
    /// </summary>
    [CLSCompliant(true)]
    public class SscZingerSortBuilder : SqlSortBuilder<SscZingerColumn>
    {
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the SscZingerSqlSortBuilder class.
		/// </summary>
		public SscZingerSortBuilder() : base() { }

		#endregion Constructors

    }    
    #endregion SscZingerSortBuilder
	
} // end namespace
